package com.unitreport.service;

import com.unitreport.dao.UnitCmdDaoI;
import com.unitreport.dao.UnitCmdDaoImpl;
import com.unitreport.domain.UnitCmd;

public class ValidaterImpl implements ValidaterI {

	public void validate(UnitCmd unitCmd) {
		String executeInfo = unitCmd.getExecuteInfo();
		
		String rightKeywords = "[INFO] BUILD SUCCESS";
		
		String failedKeywords = "[INFO] BUILD FAILURE";
		
		UnitCmdDaoI unitCmdDao = new UnitCmdDaoImpl();
		
		if(executeInfo != null) {
			if(executeInfo.indexOf(rightKeywords) == -1) {
				if(executeInfo.indexOf(failedKeywords) != -1) {
					unitCmd.setErrorDetails(executeInfo);
					unitCmdDao.saveFailedDetails(unitCmd);
				}else {
					unitCmd.setErrorDetails(executeInfo);
					unitCmdDao.saveErrorDetails(unitCmd);
				}
			}
		}else {
			unitCmd.setErrorDetails("no executeInfo!");
			unitCmdDao.saveErrorDetails(unitCmd);
		}
		
		
		
	}

}
